<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <include file="./Application/Admin/View/Include/easyui.html" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/init.css">
</head>

<body>
    <div class="easyui-tabs" style="width:100%;">

        <div title="权限管理" style="padding:10px">
            <table id="perm" class="easyui-datagrid" title="权限列表" style="width:100%;"
            data-options="singleSelect:true,pagination:true,collapsible:false,url:'__APP__/Perm/get_perm',method:'post'"
            toolbar="#tb"
            fitColumns="true">
            <thead>
                <tr>
                    <th data-options="field:'id',width:50">ID</th>
                    <th data-options="field:'name',width:100">权限名称</th>
                    <th data-options="field:'controller',width:100">控制器</th>
                </tr>
            </thead>
        </table>
        <div id="tb" style="padding:2px;">
            <p style="margin: 4px;">
                <button class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="newPerm()">添加权限</button>
                <button class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="editPerm()">编辑权限</button>
                <button class="easyui-linkbutton" plain="true" iconCls="icon-delete" onclick="destroyPerm()">删除权限</button>
                <button class="easyui-linkbutton" plain="true" iconCls="icon-refresh" onclick="javascript:$('#perm').datagrid('reload')">刷新</button>
            </p>
        </div>

    </div>

</div>

<!--  栏目表单Dialog  -->
<div id="dlg" class="easyui-dialog" style="width:50%;height:300px;padding:10px 0px; text-align:center;"
closed="true" buttons="#dlg-buttons">
<form id="fm" method="post" novalidate>
    <div class="fitem">
        <label>权限名称:</label>
        <input name="name" class="easyui-textbox" required="true">
    </div>
    <div class="fitem">
        <label>权限控制器:</label>
        <input name="controller" class="easyui-textbox" required="true">
    </div>
    <div class="fitem">
        <label>权限描述:</label>
        <input class="easyui-textbox" name="desc" data-options="multiline:true" style="height:60px">
    </div>
</form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick= "savePerm();" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>

</div>


<script>

    var url;
    function newPerm(){
        $('#dlg').dialog('open').dialog('setTitle','添加权限');
        $('#fm').form('clear');
        url = '__APP__/Perm/save';
    }

    function editPerm(){
        var row = $('#perm').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('setTitle','编辑权限');
            $('#fm').form('load',row);  //将表中的数据填充到dialog中
            url = '__APP__/Perm/update/id/'+row.id;
        }else{
            $.messager.alert('Error','请选中一行记录！'); 
        }
    }

    function savePerm() {
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');  //验证表单
            },
            success: function(result){
                var result = eval('('+result+')');  //change the JSON string to javascript object    
                if (result.errorMsg){
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#dlg').dialog('close');
                    $('#perm').datagrid('reload')
                }
            }
        });
    }


    function destroyPerm(){
        var row = $('#perm').datagrid('getSelected');
        if (row){
            $.messager.confirm('确认删除','确认删除吗?',function(r){
                if (r){
                    $.post('__APP__/Perm/del',{id:row.id},function(result){
                        if (result.success){
                            $('#perm').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    },'json');
                }
            });
        }else{
            $.messager.alert('Error','请选中一行记录！'); 
        }
    }

</script>

</body>
</html>